<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        td {
            border: 1px solid rgb(0, 0, 0);
        }

        table {
            border-collapse: collapse;
        }
    </style>
</head>

<body>
    <table>
        <thead>
            <tr>
                <td><input type="checkbox" id="check"></td>
                <td>水果</td>
                <td>工具</td>
                <td>手机</td>
                <td>电脑</td>
            </tr>
        </thead>
        <tbody id="tb">
            <tr>
                <td><input type="checkbox"></td>
                <td>苹果</td>
                <td>栗子</td>
                <td>苹果</td>
                <td>栗子</td>

            </tr>
            <tr>
                <td><input type="checkbox"></td>
                <td>苹果</td>
                <td>栗子</td>
                <td>苹果</td>
                <td>栗子</td>
            </tr>
            <tr>
                <td><input type="checkbox"></td>
                <td>苹果</td>
                <td>栗子</td>
                <td>苹果</td>
                <td>栗子</td>
            </tr>
            <tr>
                <td><input type="checkbox"></td>
                <td>苹果</td>
                <td>栗子</td>
                <td>苹果</td>
                <td>栗子</td>
            </tr>
        </tbody>
    </table>
    <script>
        var hang = document.querySelector('tbody').querySelectorAll('tr');
        for (var i = 0; i < hang.length; i++) {
            hang[i].onmouseover = function () {
                this.style.backgroundColor = 'rgb(22, 223, 206)';
            }
            hang[i].onmouseout = function () {
                this.style.backgroundColor = '';
            }
        }
        var check = document.getElementById('check');
        var checks = document.getElementById('tb').getElementsByTagName('input');
        check.onclick = function () {
            console.log(this.checked);
            for (i = 0; i < checks.length; i++) {
                checks[i].checked = 'checked';
            }
        }
        for(var i = 0;i<checks.length;i++){
            
            checks[i].onclick =function(){
                var flag = true;
                for(var i = 0;i<checks.length;i++){
                    if(! checks[i].checked){
                    flag =false;
                    break;
                }
                }
                checks.checked = flag;
                
            }
        }
    </script>
</body>

</html>